﻿using DDDSample.Application.Interfaces;
using DDDSample.Application.Services;
using DDDSample.Domain.CommandHandlers;
using DDDSample.Domain.Commands;
using DDDSample.Domain.Core.Bus;
using DDDSample.Domain.EventHandlers;
using DDDSample.Domain.Events;
using DDDSample.Domain.Interfaces;
using DDDSample.Domain.Notifications;
using DDDSample.Infrastruct.Data.Bus;
using DDDSample.Infrastruct.Data.Context;
using DDDSample.Infrastruct.Data.Repository;
using DDDSample.Infrastruct.Data.UoW;
using MediatR;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace DDDSample.Extensions
{
    public class NativeInjectorBootStrapper
    {
        public static void RegisterServices(IServiceCollection services)
        {
            // 注入 Application 应用层
            services.AddScoped<IStudentAppService,StudentAppService>();

            // 注入 Infra - Data 基础设施数据层
            services.AddScoped<IStudentRepository,StudentRepository>();

            // 注入 上下文
            services.AddScoped<StudyContext>();

            // 注入中介总线接口
            services.AddScoped<IMediatorHandler,InMemoryBus>();

            // 注入工作单元
            services.AddScoped<IUnitOfWork,UnitOfWork>();

            // Domain-->Commands
            services.AddScoped<IRequestHandler<RegisterStudentCommand, Unit>, StudentCommandHandler>();
            services.AddScoped<IRequestHandler<UpdateStudentCommand, Unit>, StudentCommandHandler>();
            services.AddScoped<IRequestHandler<RemoveStudentCommand, Unit>, StudentCommandHandler>();

            // Domain-->Event
            services.AddScoped<INotificationHandler<StudentRegisteredEvent>, StudentEventHandler>();
            services.AddScoped<INotificationHandler<StudentUpdatedEvent>, StudentEventHandler>();
            services.AddScoped<INotificationHandler<StudentRemovedEvent>, StudentEventHandler>();

            services.AddScoped<INotificationHandler<DomainNotification>, DomainNotificationHandler>();
        }
    }
}
